package com.tedu._02notice.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    private Integer state;//响应状态码
    private String message;//提示消息
    private Object data;//具体数据

    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }
    public JsonResult(StatusCode statusCode ,Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }
    /**
     * 封装两个静态方法，针对于 ！操作成功！，操作失败无需封装
     * 1。正对于操作成功没有返回值得控制器方法
     * 2.针对操作成功有返回值的控制器方法
     * */
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public static JsonResult ok(){
//        return new JsonResult(StatusCode.OPERATION_SUCCESS);
        return JsonResult.ok(null);
    }
}
